﻿@model ArticleModel
@using CAF.Infrastructure.Core.Domain.Cms.Channels;
@if (Model.ShowSpecificationAttributes && Model.CategoryShowType != CategoryShowType.CheckBox)
{
    if (Model.ArticleSpecificationAttributeModels.Count > 0)
    {
    <script type="text/javascript">
        $(function () {
            var count=@Model.ArticleSpecificationAttributeModels.Count;
            if (count > 0)
            {
                getdata();
            }
        });

        $(document).ready(function () {
           

            //改变时修改数据
            $(document).on("change", "#addfare tbody tr input", function () {
                getdata();
            })
        });


        //拿数据
        function getdata() {
            var trs = $("#addfare tbody tr");
            var trArr = [];
            $.each(trs, function (e) {
                var trObj = {};
                trObj.SpecificationAttributeOptionId = $(this).find("select.spaoption-select").val();
                trObj.AllowFiltering = $(this).find("input.s_allowfiltering").prop("checked")?"true":"false";
                trObj.ShowOnArticlePage = $(this).find("input.s_showonarticlepage").prop("checked")?"true":"false";
                trObj.DisplayOrder = $(this).find("input.s_displayorder").val();
                trArr.push(trObj);
            })
            $("input[name='SpaValues']").val(JSON.stringify(trArr));
        }
    </script>
    <div class="form-body">
        <div class="form-group">
            <label class="control-label col-md-2">
                <span class="help-block m-b-none text-muted"><i class="fa fa-info-circle text-info"></i>内容属性</span>
            </label>
            <div class="col-md-10">
                <input type="hidden" name="SpaValues" value="[]">
                <div class="row">
                    <div class="col-md-12 ">
                        <section class="panel panel-default">

                            <div class="table-responsive">
                                <table class="table  b-t b-light" id="addfare">
                                    <thead>
                                        <tr>
                                            <th style="width: 60px">属性</th>
                                            <th>属性值</th>
                                            <th class="" style="width: 120px;display:none;">允许过滤</th>
                                            <th class="" style="width: 120px;display:none;">在内容页面显示</th>
                                            <th class="" style="width: 120px">排序</th>
                                            <th class="" style="width: 120px"></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @if (Model.ArticleSpecificationAttributeModels.Count > 0)
                                        {

                                            foreach (var articleSpecificationAttributeModel in Model.ArticleSpecificationAttributeModels)
                                            {
                                                var randNum = Guid.NewGuid().ToString();
                                                <tr id="tr@randNum">
                                                    <td class=""><span class="text-dep1">@articleSpecificationAttributeModel.SpecificationAttributeName</span></td>
                                                    <td>
                                                        <select style="width:260px" class="form-control spaoption-select">
                                                            @foreach (var specificationAttributeOption in articleSpecificationAttributeModel.SpecificationAttributeOptions)
                                                            {
                                                                <option @(specificationAttributeOption.select ? "selected" : "") value="@specificationAttributeOption.id">@specificationAttributeOption.name</option>
                                                            }
                                                        </select>
                                                    </td>
                                                    <td class="" style="display:none;"><input type="checkbox" @(articleSpecificationAttributeModel.AllowFiltering ? "checked" : "") class="check-box s_allowfiltering"></td>
                                                    <td class="" style="display:none;"><input type="checkbox" @(articleSpecificationAttributeModel.ShowOnArticlePage ? "checked" : "") class="check-box s_showonarticlepage"></td>
                                                    <td class=""><input type="text" value="@articleSpecificationAttributeModel.DisplayOrder" class="form-control s_displayorder"></td>
                                                    <td class=""><span class="pull-right"> <a href="javascript:;" class="text-info remove_fare">删除</a></span></td>
                                                </tr>
                                            }

                                        }
                                    </tbody>
                                </table>
                            </div>
                            <footer class="panel-footer"></footer>
                        </section>
                    </div>

                </div>

            </div>
        </div>
    </div>
    }
}


